<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/5/20
 * Time: 14:09
 */
namespace app\index\controller;
use app\api\model\RoomOrdersModal;
use app\common\controller\BaseController;
use function PHPSTORM_META\elementType;
use think\Validate;
class RoomOrder extends BaseController{

    //查询订单
    public function queryOrder(){
        $page = input("get.page",1);
        $limit = input("get.limit",5);
        $account = input('get.account');
        $policeStation = input('get.policeStation');
        $model = new RoomOrdersModal();
        $data = $model->alias('a')
            ->join('think_rooms b','b.room_code = a.room_code','left')
            ->join('think_user_room c','b.id=c.room_id','left')
            ->join('think_app_users d','c.uid= d.id','left')
            ->join('think_police_station e','e.id=b.police_station_id','left')
            ->field('a.*,b.police_station_id,b.id,c.*,d.*,e.*')
            ->where('d.account|a.custom_id_card','like','%'.$account.'%')
            ->page($page,$limit)
            ->select();
        for($i=0;$i<count($data);$i++){
            if($data[$i]->status==1){
                $data[$i]->status="入住";
            }else{
                $data[$i]->status="退房";
            }
            if($data[$i]->custom_sex==1){
                $data[$i]->custom_sex="男";
            }else{
                $data[$i]->custom_sex="女";
            }
        }
        return $this->ajaxReturn(200,$data,"修改成功");
    }

    //条件获取数据库总数据条数
    public function getPageLimit(){
        $account = input('get.account');
        $model = new RoomOrdersModal();
        $data = $model->alias('a')
            ->join('think_rooms b','b.room_code = a.room_code','left')
            ->join('think_user_room c','b.id=c.room_id','left')
            ->join('think_app_users d','c.uid= d.id','left')
            ->join('think_police_station e','e.id=b.police_station_id','left')
            ->field('a.room_code,b.police_station_id,b.id,c.*,d.*,e.*')
            ->where('d.account|a.custom_id_card','like','%'.$account.'%')
            ->count();
        return $this->ajaxReturn(200,$data,'获取成功');
    }
}